package com.lecture.java8.stream;

import org.assertj.core.util.Lists;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * @author luyn
 * @version 1.0
 * @description
 * @date 2021/3/18 14:15
 */
public class ListToMap {

    public static void main(String[] args) {
        List<User> userList = Lists.newArrayList(
                new User("A","张三"),
                new User("B","李四"),
                new User("D","李四2"),
                new User("D","李四3"),
                new User("D","李四4"),
                new User("C","王五")
        );
        Map<String, String> map = userList.stream().collect(Collectors.toMap(User::getId, User::getName, (user1, user2) -> user1));
        map.forEach((k,v)-> {
            System.out.println("K：" + k + "-----V：" + v);
        });

        Map<String, User> map2 = userList.stream().collect(Collectors.toMap(User::getId, (user -> user)));
        map2.forEach((k,v)-> {
            System.out.println(k  + "     " + v);
        });
    }
}
